package org.jeecg.modules.api.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.util.MD5Util;
import org.jeecg.modules.api.PaperVo;
import org.jeecg.modules.content.entity.ConContentPerformance;
import org.jeecg.modules.content.service.IConContentPerformanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@Api(tags="纸媒登载接口")
@RestController
@RequestMapping("/api/article/")
public class PaperArticleController {
    @Autowired
    private IConContentPerformanceService conContentPerformanceService;

    /**
     * 分页列表查询
     * @param paperVo
     * @return
     */
    @AutoLog(value = "内容审核-分页列表查询")
    @ApiOperation(value="内容审核-分页列表查询", notes="内容审核-分页列表查询")
    @PostMapping(value = "/callBack")
    public Result<?> update(@RequestBody PaperVo paperVo) {
        String token  = MD5Util.MD5Encode(paperVo.getArticleId()+"xinke", "utf-8");
        if (!paperVo.getToken().equals(token)){
             return  Result.error("token不正确");
        }
        UpdateWrapper<ConContentPerformance> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("template_id",paperVo.getArticleId());
        ConContentPerformance conContentPerformance = new ConContentPerformance();
        conContentPerformance.setLandingType(2);
        conContentPerformance.setCallbackTime(new Date());
        conContentPerformance.setLandStatus(1);

       Boolean flag = conContentPerformanceService.update(conContentPerformance,updateWrapper);
     if(flag){
         return  Result.ok();

     }else {
         return   Result.error("未更新成功");
     }


    }


    public static void main(String[] args) {
        String token  = MD5Util.MD5Encode("xinke", "utf-8");

        System.out.println(token);
    }
}
